<script lang="ts" setup>
import { ref, onBeforeMount, onMounted, onUnmounted } from "vue";
// 导入图标工具
import { OfficeBuilding } from "@/utils/icons.js";

/*职位信息接口定义*/
interface Job {
    id: string;
    title: string;
    salary: string;
    location: string;
    experience: string;
    education: string;
    company: string;
    industry: string;
    financing: string;
}

/**
 * 行业分类接口定义
 * @property label - 行业显示名称
 * @property value - 行业值
 */
interface Industry {
    label: string;
    value: string;
}

// 组件props定义
const props = defineProps<{
    jobs: Job[]; // 职位列表数据
    industries: Industry[]; // 行业分类数据
    activeIndustry: string; // 当前选中行业
}>();

// 组件事件定义
const emit = defineEmits<{
    (e: "tabClick", tab: TabsPaneContext): void; // 行业标签点击事件
    (e: "viewMore"): void; // 查看更多点击事件
}>();

/**
 * 行业标签点击处理
 * @param tab - 被点击的标签页上下文
 */
const handleTabClick = (tab: TabsPaneContext) => {
    emit("tabClick", tab); // 触发tabClick事件
};

// 路由实例
import { useRouter } from "vue-router";
const router = useRouter(); // 获取路由实例

/**
 * 查看更多按钮点击处理
 */
const handleViewMore = () => {
    router.push({
        path: "/position",
    }); // 跳转到职位列表页
};

/**
 * 跳转到职位详情页
 * @param id - 职位ID
 */
const gotoJobDetail = (id: string) => {
    router.push({
        path: "/position",
        query: { id },
    });
};

// Boss直聘logo URL
const companyLogoUrl =
    "https://img.bosszhipin.com/beijin/upload/com/logo/20210323/aab1b65662224a865a9b6ba9aceaab02babfa420ecc134d2606b05aa8114130d.png?x-oss-process=image/resize,w_100,limit_0";

//生命周期种子
onBeforeMount(() => {});
onMounted(() => {});
onUnmounted(() => {});

// 定义TabsPaneContext类型
interface TabsPaneContext {
    props: {
        name: string;
        [key: string]: any;
    };
    [key: string]: any;
}
</script>

<template>
    <!-- 热招职位模块 -->
    <div class="hot-jobs">
        <!-- 模块标题 -->
        <h2 class="section-title">热招职位</h2>

        <!-- 行业标签页 -->
        <el-scrollbar>
            <el-tabs
                :model-value="activeIndustry"
                class="demo-tabs"
                @update:model-value="(val: string) => emit('tabClick', { props: { name: val } } as TabsPaneContext)"
            >
                <!-- 遍历行业数据 -->
                <el-tab-pane v-for="item in industries" :key="item.value" :label="item.label" :name="item.value" />
            </el-tabs>
        </el-scrollbar>

        <!-- 职位列表 -->
        <el-row :gutter="20" justify="center" class="job-list">
            <!-- 遍历职位数据 -->
            <el-col
                v-for="(job, index) in jobs"
                :key="index"
                :xs="24"
                :sm="12"
                :md="8"
                :lg="8"
                :xl="8"
                class="job-card-col"
            >
                <!-- 职位卡片 -->
                <el-card class="job-card" @click="gotoJobDetail(job.id)">
                    <!-- 卡片头部区域 -->
                    <template #header>
                        <div class="card-header">
                            <!-- 职位标题和薪资 -->
                            <div class="job-title">
                                <span>{{ job.title }}</span>
                                <span class="salary">{{ job.salary }}</span>
                            </div>
                            <!-- 职位要求 -->
                            <div class="job-requirements">
                                <span>{{ job.location }}</span>
                                <el-divider direction="vertical" />
                                <span>{{ job.experience }}</span>
                                <el-divider direction="vertical" />
                                <span>{{ job.education }}</span>
                            </div>
                        </div>
                    </template>

                    <!-- 公司信息 -->
                    <div class="company-info">
                        <div class="company-left">
                            <img :src="companyLogoUrl" class="company-logo" alt="公司logo" />
                            <span>{{ job.company }}</span>
                        </div>
                        <div class="company-right">
                            <span>{{ job.industry }}</span>
                            <!-- 融资阶段标签 -->
                            <el-tag
                                class="financing-tag"
                                :type="job.financing === '未融资' ? 'info' : 'success'"
                                size="small"
                            >
                                {{ job.financing }}
                            </el-tag>
                        </div>
                    </div>
                </el-card>
            </el-col>
        </el-row>

        <!-- 查看更多按钮 -->
        <div class="view-more-container">
            <el-button class="view-more" @click="router.push('/position')"> 查看更多 </el-button>
        </div>
    </div>
</template>

<style lang="less" scoped>
/* 热招职位模块样式 */
.hot-jobs {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;

    /* 模块标题样式 */
    .section-title {
        text-align: center;
        margin-bottom: 40px;
        font-size: 32px;
        font-weight: 600;
    }

    /* 职位列表样式 */
    .job-list {
        margin: 0 -10px;
    }

    /* 职位卡片列样式 */
    .job-card-col {
        margin-bottom: 20px;
        padding: 0 10px;
    }

    /* 职位卡片样式 */
    .job-card {
        height: 100%;
        transition: all 0.3s;
        border-radius: 8px;

        /* 悬停效果 */
        &:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
        }

        /* 卡片头部样式 */
        .card-header {
            padding: 12px 16px;

            /* 职位标题样式 */
            .job-title {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 8px;

                span:first-child {
                    font-size: 16px;
                    font-weight: 600;
                }

                /* 薪资样式 */
                .salary {
                    color: #f56c6c;
                    font-weight: bold;
                    font-size: 18px;
                }
            }

            /* 职位要求样式 */
            .job-requirements {
                color: #999;
                font-size: 12px;
                display: flex;
                align-items: center;

                :deep(.el-divider) {
                    margin: 0 8px;
                    background-color: #ddd;
                }
            }
        }

        /* 公司信息样式 */
        .company-info {
            padding: 12px 16px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 14px;

            .company-left {
                display: flex;
                align-items: center;

                .company-logo {
                    width: 20px;
                    height: 20px;
                    margin-right: 8px;
                    object-fit: contain;
                }
            }

            .company-right {
                display: flex;
                align-items: center;
                gap: 8px;

                .el-tag {
                    border-radius: 4px;
                }
            }
        }
    }

    /* 查看更多按钮样式 */
    .view-more-container {
        text-align: center;
        padding: 10px;

        .view-more {
            padding: 12px 40px;
            background-color: #e6f7ff;
            border-color: #1890ff;
            color: #1890ff;
            font-weight: bold;
            transition: all 0.3s;

            &:hover {
                background-color: #1890ff;
                color: white;
            }
        }
    }
}

/* 移动端响应式样式 */
@media (max-width: 768px) {
    .hot-jobs {
        padding: 20px 10px;

        /* 移动端卡片列样式 */
        .job-card-col {
            padding: 0 5px;
        }

        /* 移动端卡片样式调整 */
        .job-card {
            .card-header {
                padding: 8px 12px;

                .job-title {
                    flex-direction: column;
                    align-items: flex-start;
                    gap: 8px;
                }
            }

            .company-info {
                flex-direction: column;
                align-items: flex-start;
                gap: 8px;
            }
        }
    }
}
</style>
